#ifndef LINUX_LIST_H__
#define LINUX_LIST_H__

struct list_head
{
	struct list_head *prev;
	struct list_head *next;
};
#define LIST_HEAD_INIT(name) {&(name),&(name)}

#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)

static inline void __list_add(struct list_head *new,
                              struct list_head *prev,
                              struct list_head *next)
{
        next->prev = new;
        new->next = next;
        new->prev = prev;
        prev->next = new;
}

inline void list_add(struct list_head *new, struct list_head *head) 
{ 
        __list_add(new, head, head->next); 
} 


#define __list_for_each(pos, head) \
        for (pos = (head)->next; pos != (head); pos = pos->next)
/*
ptr cur
type struct score_st
member node
*/

/*
 * 得到指针组在用户结构体中的“ 高度”
 * */
#define offsetof(TYPE, MEMBER)  ((size_t)&((TYPE *)0)->MEMBER)

/*
 * ptr(指针组)    -     "高度"  =    用户结构体的地址
 * */
#define container_of(ptr, type, member)                      \
      ( {(type *)( (char *)ptr - offsetof(type,member) );})



/*
#define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
        (type *)( (char *)__mptr - offsetof(type,member) );})
*/

/* 
 * 得到用户结构体
 * @ptr:	struct list_head *
 * @type:	外部struct 类型
 * %member:	指针组的名字
 * */
#define list_entry(ptr, type, member) \
        container_of(ptr, type, member)



#endif
